<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>AI 论坛</title>
		<link rel="stylesheet" media="screen" href="css/login.css">
	</head>
	<body>
		<!-- particles.js container -->
		<div id="particles-js" style="display: flex;align-items: center;justify-content: center">
			<canvas class="particles-js-canvas-el" style="width: 100%; height: 100%;" width="472" height="625"></canvas>
		</div>
		<div class="apTitle">AI 论坛</div>
		<div class="logcon">
			<input id='num' type="text" placeholder="账号"><br>
			<input id='pswd' type="password" placeholder="密码"><br><br>
			<button type="button" onclick='getData_1()'>登录</button>
			<button onclick='getData_2()' type="button">注册</button>
		</div>
		

		<!-- scripts -->
		<script src="js/JQ.js"></script>
		<script src="js/login.js"></script>
		<script src="js/loginApp.js"></script>
		<script src="js/jQsession.js"></script>
		<script>
			function changeImg() {
				var pic = document.getElementById('picture');
				console.log(pic.src)
				if (pic.getAttribute("src", 2) == "img/check.png") {
					pic.src = "img/checked.png"
				} else {
					pic.src = "img/check.png"
				}
			}
			//////////////////////////////////////////////////////
			var getData_1 = function(){
				var loginNm = document.getElementById("num").value;
		        var pwd = document.getElementById("pswd").value;
		        //self.alert("登录名：" + loginNm + "\n密码：" + pwd);
		        
		        $.post("login",{
					number:loginNm,
					passwd:pwd
				},
				function(data,status){
					//alert("数据: \n" + data + "\n状态: " + status);
					//window.location.href="index.html";
					var jsonArray = JSON.parse(data);
					console.log('前端：'+jsonArray);
					for(var i=0;i<jsonArray.length;i++)
					{
						console.log('前端：'+jsonArray[0].name);
						if(jsonArray[0].name == "ture"){
							alert("登录成功");
							$.session.set('name', loginNm);
							//var name = $.session.get('name');
							//alert(name);
							window.location.replace("index.html");
						}	
						else
						{
							alert("账号或密码错误");
							location.reload();
						}
					}
				});
			}
			var getData_2 = function(){
				window.location.replace("register.html");
				/*
				var loginNm = document.getElementById("num").value;
		        var pwd = document.getElementById("pswd").value;
		        self.alert("登录名：" + loginNm + "\n密码：" + pwd);
		        
		        $.post("servlet.register",{
					number:loginNm,
					passwd:pwd
				},
				function(data,status){
					alert("\n状态: " + status);
					window.location.replace("index.html");
				});
		        */
			}
		</script>

	</body>
</html>
